# clear and libraries
rm(list=ls())
packs = c('tidyverse', 'readxl', 'hrbrthemes')
source("repFile/r/helpers.R")
loadPkg(packs)


# load all data
df = 
  read_excel('repFile/data/WVS_Confidence_The_police.xls')

df2 = 
  gather(df, China:Egypt, key = 'country', value = 'percent') %>% 
  filter(country != 'ANSWER') %>% 
  mutate(answer = rep(df$ANSWER, length(unique(country)))) %>% 
  filter(country != 'Kazakhstan')

# shorten response for plot
df2$answer[df2$answer == 'Not very much'] <- "Not much"

# factorize answers
df2$answer = factor(df2$answer, levels = unique(df2$answer))

# divide by 100
df2$percent = df2$percent/100

ggplot(df2, aes(x = answer, y = percent, fill = answer)) + 
  geom_col() + 
  facet_wrap(~country, scales = 'free_x') + 
  theme_ipsum_rc(grid = 'Y') + 
  scale_y_percent() + 
  labs(x = '', y = '', 
       title = "Trust in the Police in Select Countries", 
       subtitle = "Source: World Values Survey.") + 
  theme(axis.text.x = element_blank(), legend.title = element_blank(), 
        legend.position = 'top') + 
  scale_fill_grey()
ggsave('repFile/paper/figures/wvs-police-trust.pdf', device = cairo_pdf)  
ggsave('repFile/paper/figures/wvs-police-trust.tiff', device = "tiff")  

